//
//  UIImage+Extension.swift
//  微博分支添加图片
//
//  Created by JJ on 15/9/10.
//  Copyright © 2015年 JJ. All rights reserved.
//

import UIKit

extension UIImage{
    
    func scaleImageToWidth(width:CGFloat) -> UIImage{
        
        if size.width < width{
            return self
        }
        let heigh=width * size.height/size.width
        let s=CGSize(width: width, height: heigh)
        
        UIGraphicsBeginImageContext(s)
        
        drawInRect(CGRect(origin: CGPointZero, size: s))
        
        let resualt=UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return resualt
        
    }
}
